Skip to content

Reduce allocations when Activity is enabled #11020

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 10, 2019

Conversation

davidfowl
Copy link
Member

@davidfowl davidfowl commented Jun 9, 2019

  • Remove string allocations caused by DiagnosticSource.Stop/StartActivity
  • Pass the HttpContext directly as the object for StartActivity and StopActivity to avoid the anonymous object allocation.
  • Though it's a bit ugly, added an HttpContext property to DefaultHttpContext to avoid breaking back-compat (which had to do reflection to get the HttpContext property anyways)

Contributes to #9594

Before:
image

After:
image

- Remove string allocations caused by DiagnosticSource.Stop/StartActivity
- Pass the HttpContext directly as the object for StartActivity and StopActivity to avoid the anonymous object allocation.
- Though it's a bit ugly, added an HttpContext property to DefaultHttpContext to avoid breaking back-compat (which had to do reflection to get the HttpContext property anyways)
- Mark HttpContext field as editable browsable never
- Ran code check
Co-Authored-By: Christopher Watford <[email protected]>
@davidfowl davidfowl merged commit d4a982f into master Jun 10, 2019
@ghost ghost deleted the davidfowl/reduce-activity-allocs branch June 10, 2019 20:37
@davidfowl
Copy link
Member Author

cc @lmolkova @SergeyKanzhelev as an FYI, this should be non breaking though.

@@ -278,7 +279,7 @@ private Activity StartActivity(HttpContext httpContext, out bool hasDiagnosticLi
if (_diagnosticListener.IsEnabled(ActivityStartKey))
{
hasDiagnosticListener = true;
_diagnosticListener.StartActivity(activity, new { HttpContext = httpContext });
StartActivity(activity, httpContext);
Copy link

@lmolkova lmolkova Jun 14, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this and we may be able to update listener in time for 3.0 to support it. But it is breaking (i.e. there is no HttpContext property on HttpContext type), everyone who attempts to get it will fail.

Copy link

@lmolkova lmolkova Jun 14, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ooops, you've added property on HttpConetxt 😂

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

HttpContext.HttpContext 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-hosting Includes Hosting
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants